package util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public class DbUtils {
	
	private static final Logger logger = Logger.getLogger(DbUtils.class);
	
	public static void closeQuietly(ResultSet rs)
	{
		try
		{
			if (rs != null)
			{
				rs.close();
			}
		}
		catch (SQLException e)
		{
			logger.error(e.getMessage(), e);
		}
	}

	public static void closeQuietly(PreparedStatement pres)
	{
		try
		{
			if (pres != null)
			{
				pres.close();
			}
		}
		catch (SQLException e)
		{ 
			logger.error(e.getMessage(), e);
		}
	}

	public static void closeQuietly(Connection conn)
	{
		try
		{
			if (conn != null)
			{
				conn.close();
			}
		}
		catch (SQLException e)
		{ 
			logger.error(e.getMessage(), e);
		}
	}
	
	public static void closeQuietly(PreparedStatement stmt, Connection conn)
	{
		try
		{
			closeQuietly(stmt);
		}
		finally
		{
			closeQuietly(conn);
		}
	}

	public static void closeQuietly(ResultSet rs, PreparedStatement stmt, Connection conn)
	{
		try
		{
			closeQuietly(rs);
		}
		finally
		{
			try
			{
				closeQuietly(stmt);
			}
			finally
			{
				closeQuietly(conn);
			}
		}
	}
}
